<template>
<div class="TeamJuJia">
  <div class="divList"
       @click="clickTeam(item)"
       v-for="(item, index) in teamList" :key="index">
    <img :src="item.team_icon" class="photo" alt="">
    <ul>
      <li>
        <span class="name">
              {{item.team_name}}
              <a style="font-size: 13px;font-weight: 500">（{{item.count}}人）</a>
        </span>
        <router-link :to="{path: '/JuJiaTeamXiangmu',
         query: {userid: userid,
         team_id: item.team_id,
         title: item.team_name,
         type: type}}">
           <span style="color: #1da4f2" v-show="!login">
            团队详情
            <img src="../../../assets/更多蓝.png" alt="">
          </span>
        </router-link>
      </li>
      <li>
        <span >团队长：{{item.NICK_NAME}}</span>
        &nbsp;
        &nbsp;
        <span style="font-weight: 500;font-size: 13px !important;">{{item.MAJOR}}</span>
        <span>&nbsp;|&nbsp;</span>
        <span style="font-weight: 500;font-size: 13px !important;">{{item.DEPART}}</span>
      </li>
      <li>
        <span class="jieShao">{{item.HOSPITAL_NAME}}</span>
        <button class="biaoqian">{{item.GRADE}}</button>
      </li>
    </ul>
  </div>
  <van-loading v-show="isLoading" size="24px" style="width: 100%;height: 80vh;
    display:flex;align-items:center;justify-content:center; color: #1da4f2" vertical>
    加载中...
  </van-loading>
  <van-empty
    style="width: 100%;height: 60vh;"
    v-show="teamList.length <= 0 && isLoading === false"
    class="custom-image"
    :image="require('../../../assets/空两本书.png')"
    :description=" `暂无`+emptyText+`数据`"
  />
</div>
</template>

<script>
export default {
  name: 'TeamJuJia',
  data () {
    return {
      userid: this.$route.query.userid,
      type: this.$route.query.type,
      teamList: [],
      isLoading: true,
      login: this.$route.query.login,
      team_type: this.$route.query.team_type,
      team_id: this.$route.query.team_id
    }
  },
  computed: {
    searchVal () {
      let val = ''
      if (this.$route.query.searchVal) {
        val = this.$route.query.searchVal
      }
      return val
    },
    emptyText () {
      let text = ''
      if (this.searchVal) {
        text = '符合条件'
      }
      return text
    }
  },
  watch: {
    searchVal (val1, val2) {
      if (val1 !== val2) {
        this.getTeamList()
      }
    }
  },
  mounted () {
    // 获取团队列表
    this.getTeamList()
  },
  methods: {
    // 点击团队
    clickTeam (item) {
      if (this.login) {
        this.$router.push({path: '/TeamHome',
          query: {
            userid: this.userid, // 医生userid
            topActive: 0,
            id: item.team_id,
            team_id: item.team_id
          }})
      }
    },
    // 获取团队列表
    getTeamList () {
      this.teamList = []
      this.isLoading = true
      this.$http.TeamList({
        name: this.searchVal,
        team_type: this.team_type
      })
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            if (this.team_id) {
              res.data.data.forEach((curr) => {
                if (curr.team_id == this.team_id) {
                  this.teamList.push(curr)
                }
              })
            } else {
              this.teamList = res.data.data
            }
            this.isLoading = false
          } else {
            this.isLoading = false
            this.$toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          this.isLoading = false
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    }
  }
}
</script>

<style scoped lang="scss">
.TeamJuJia{

}
.divList{
  width: 100%;
  padding: 10px 15px;
  box-sizing: border-box;
  background: #FFFFFF;
  margin-bottom: 8px;
  display: flex;
  font-size: 15px;
  ul{
    flex: 1;
    margin-left: 8px;
    li{
      min-height: 25px;
      &:first-child{
        display: flex;
        justify-content: space-between;
        img {
          width: 7px;
          height: 12px;
        }
      }
    }
  }
}
.biaoqian{
  min-width: 44px;
  height: 18px;
  border-radius: 15px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  background: transparent;
  color: #1DA4F2;
  border: 1px solid;
  font-size: 11px;
  margin-left: 8px;
}
.photo{
  width: 60px;
  height: 60px;
  border-radius: 50%;
}
</style>
